#include "maincontroller.h"

MainController *MainController::m_instance=nullptr;
MainController::MainController()
    :m_mainwindow(nullptr)
    ,m_userhome(nullptr)
    ,m_usermanagement(nullptr)
    ,m_changview(nullptr)
    ,m_register(nullptr)
    ,h_insert(nullptr)
//    ,h_find(nullptr)
{

}

MainController *MainController::getMainController()
{
    if(m_instance==nullptr){
        m_instance=new MainController();
    }
    return m_instance;
}

void MainController::initMainWindow(MainWindow *m)
{
        m_mainwindow=m;
}

void MainController::showMainWindow()
{
    if(m_mainwindow!=nullptr){
        m_mainwindow->show();
    }
}

void MainController::hideMainWindow()
{
    if(m_mainwindow!=nullptr){
        m_mainwindow->hide();
    }
}

void MainController::showUserHome()
{
    if(m_userhome==nullptr){
        m_userhome=new UserHome();
    }
    m_userhome->show();
}

void MainController::hideUserHome()
{
    if(m_userhome!=nullptr){
        delete  m_userhome;
        m_userhome = nullptr;
    }
}

void MainController::showUserManagement()
{
    if(m_usermanagement==nullptr){
        m_usermanagement=new UserManagement();
    }
    m_usermanagement->show();
}

void MainController::hideUserManagement()
{
    if(m_usermanagement!=nullptr){
        m_usermanagement->hide();
    }
}

void MainController::showChangView()
{
    if(m_changview==nullptr){
        m_changview=new ChangeView();
    }
    m_changview->show();
}

void MainController::hideChangView()
{
    if(m_changview!=nullptr){
        m_changview->hide();
    }
}

void MainController::deleteChangView()
{
    if(m_changview!=nullptr)
    {
        delete m_changview;
        m_changview = nullptr;
    }
}

//新增界面
void MainController::showinsert()
{
    if(h_insert == nullptr)
    {
        h_insert = new insertproduck();
    }
    h_insert->show();
}

void MainController::deleteinsert()
{
    if(h_insert!=nullptr)
    {
        h_insert->hide();
        delete h_insert;
        h_insert = nullptr;
    }
}

void MainController::showRegister()
{
    if(m_register == nullptr){
        m_register = new Register();
    }
    m_register->show();
}

void MainController::hideRegister()
{
    if(m_register!=nullptr){
        m_register->hide();
    }
}



//void MainController::showFind()
//{
//    if(h_find == nullptr)
//    {
//        h_find = new HomeFind();
//    }
//    h_find->show();
//}

//void MainController::deleteFind()
//{
//    if(h_find != nullptr)
//    {
//        delete  h_find;
//        h_find = nullptr;
//    }
//}

